/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufrgs.jsopa;

class Kernel {
    // Access to hardware components, including the processor

    private IntController intCn;
    private Memory mem;
    private Console con;
    private Timer tim;
    private Disco dis;
    private Processor pro;
    private Scheduler sch;
    // In the constructor goes initialization code

    public Kernel(IntController i, Memory m, Console c, Timer t, Disco d, Processor p) {
        intCn = i;
        mem = m;
        con = c;
        tim = t;
        dis = d;
        pro = p;
        sch = Main.isRoundRobinSchedulling() ? new SchedulerRR(dis) : new SchedulerFIFO(dis);
    }
    // Each time the kernel runs it have access to all hardware components

    public void run(int interruptNumber) {
        // This is the entry point: must check what happened
        Main.print("Kernel called for int " + interruptNumber);
        // save context
        sch.saveContext(pro.getPC(), pro.getReg());

        sch.treatInterruption(interruptNumber);

        pro.setPC(sch.getProcess().getPC());
        pro.setReg(sch.getProcess().getReg());
    }
}